<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.18"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>embedme: src/Logger.h Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="logo.png"/></td>
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">embedme
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.18 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_68267d1309a1af8e8297ef4c3efbcdba.html">src</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">Logger.h</div>  </div>
</div><!--header-->
<div class="contents">
<a href="_logger_8h.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;<span class="comment">/******************************************************************************</span></div>
<div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;<span class="comment"> * This file is part of libemb.</span></div>
<div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="comment"> * libemb is free software: you can redistribute it and/or modify</span></div>
<div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;<span class="comment"> * it under the terms of the GNU General Public License as published by</span></div>
<div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;<span class="comment"> * the Free Software Foundation, either version 3 of the License, or</span></div>
<div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;<span class="comment"> * (at your option) any later version.</span></div>
<div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;<span class="comment"> * libemb is distributed in the hope that it will be useful,</span></div>
<div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;<span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span></div>
<div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;<span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span></div>
<div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;<span class="comment"> * GNU General Public License for more details.</span></div>
<div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;<span class="comment"> * You should have received a copy of the GNU General Public License</span></div>
<div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;<span class="comment"> * along with libemb.  If not, see &lt;http://www.gnu.org/licenses/&gt;.</span></div>
<div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00017"></a><span class="lineno">   17</span>&#160;<span class="comment"> * Project: Embedme</span></div>
<div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;<span class="comment"> * Author : FergusZeng</span></div>
<div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160;<span class="comment"> * Email  : cblock@126.com</span></div>
<div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;<span class="comment"> * git    : https://gitee.com/newgolo/embedme.git</span></div>
<div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;<span class="comment"> * Copyright 2014~2020 @ ShenZhen ,China</span></div>
<div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;<span class="comment">*******************************************************************************/</span></div>
<div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;<span class="preprocessor">#ifndef __LOGGER_H__</span></div>
<div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;<span class="preprocessor">#define __LOGGER_H__</span></div>
<div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160; </div>
<div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;<span class="preprocessor">#include &quot;<a class="code" href="_base_type_8h.html">BaseType.h</a>&quot;</span></div>
<div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;<span class="preprocessor">#include &quot;<a class="code" href="_singleton_8h.html">Singleton.h</a>&quot;</span></div>
<div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;<span class="preprocessor">#include &quot;<a class="code" href="_file_util_8h.html">FileUtil.h</a>&quot;</span></div>
<div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;<span class="preprocessor">#include &quot;<a class="code" href="_thread_util_8h.html">ThreadUtil.h</a>&quot;</span></div>
<div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;<span class="preprocessor">#include &quot;<a class="code" href="_date_time_8h.html">DateTime.h</a>&quot;</span></div>
<div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160;<span class="preprocessor">#include &lt;map&gt;</span></div>
<div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160; </div>
<div class="line"><a name="l00037"></a><span class="lineno">   37</span>&#160;<span class="keyword">namespace </span>libemb{</div>
<div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160;<span class="preprocessor">#define LOG_INFO(logName,fmt,arg...)  do{LoggerManager::getInstance().getLogger(logName)-&gt;log(&quot;[%s]&lt;I&gt;&quot; fmt,CSTR(libemb::DateTime::currentDateTime().toString()),##arg);}while(0);</span></div>
<div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160;<span class="preprocessor">#define LOG_WARN(logName,fmt,arg...)  do{LoggerManager::getInstance().getLogger(logName)-&gt;log(&quot;[%s]&lt;W&gt;&quot; fmt,CSTR(libemb::DateTime::currentDateTime().toString()),##arg);}while(0);</span></div>
<div class="line"><a name="l00040"></a><span class="lineno">   40</span>&#160;<span class="preprocessor">#define LOG_ERR(logName,fmt,arg...)   do{LoggerManager::getInstance().getLogger(logName)-&gt;log(&quot;[%s]&lt;E&gt;&quot; fmt,CSTR(libemb::DateTime::currentDateTime().toString()),##arg);}while(0);</span></div>
<div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160; </div>
<div class="line"><a name="l00046"></a><span class="lineno"><a class="line" href="classlibemb_1_1_logger.html">   46</a></span>&#160;<span class="keyword">class </span><a class="code" href="classlibemb_1_1_logger.html">Logger</a>{</div>
<div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;<a class="code" href="_base_type_8h.html#a57e803e49526dc5ba8c1915c68708ae0">DECL_CLASSNAME</a>(<a class="code" href="classlibemb_1_1_logger.html">Logger</a>)</div>
<div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;<span class="keyword">public</span>:</div>
<div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160;    <a class="code" href="classlibemb_1_1_logger.html">Logger</a>();</div>
<div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160;    ~<a class="code" href="classlibemb_1_1_logger.html">Logger</a>();</div>
<div class="line"><a name="l00059"></a><span class="lineno">   59</span>&#160;    <span class="keywordtype">bool</span> <a class="code" href="classlibemb_1_1_logger.html#a08cccade513d4afc838bd5a021959ae8">open</a>(<span class="keyword">const</span> std::string&amp; logFileName, <a class="code" href="_base_type_8h.html#a01991db9cc388cf9815386e13465f332">uint32</a> maxSize, <a class="code" href="_base_type_8h.html#a01991db9cc388cf9815386e13465f332">uint32</a> rotations=0);</div>
<div class="line"><a name="l00063"></a><span class="lineno">   63</span>&#160;    <span class="keywordtype">void</span> <a class="code" href="classlibemb_1_1_logger.html#a9d2c0252219e63431c6c763ccd336b94">close</a>();</div>
<div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160;    <span class="keywordtype">void</span> <a class="code" href="classlibemb_1_1_logger.html#afb9febc35d54467b983d9c894fa715af">log</a>(<span class="keyword">const</span> <span class="keywordtype">char</span>* format,...);    </div>
<div class="line"><a name="l00070"></a><span class="lineno">   70</span>&#160;<span class="keyword">private</span>:</div>
<div class="line"><a name="l00071"></a><span class="lineno">   71</span>&#160;    <a class="code" href="_base_type_8h.html#a01991db9cc388cf9815386e13465f332">uint32</a> m_writens{0};</div>
<div class="line"><a name="l00072"></a><span class="lineno">   72</span>&#160;    <a class="code" href="_base_type_8h.html#a01991db9cc388cf9815386e13465f332">uint32</a> m_maxSize{0};</div>
<div class="line"><a name="l00073"></a><span class="lineno">   73</span>&#160;    <a class="code" href="_base_type_8h.html#a01991db9cc388cf9815386e13465f332">uint32</a> m_rotations{0};</div>
<div class="line"><a name="l00074"></a><span class="lineno">   74</span>&#160;    <a class="code" href="_base_type_8h.html#a01991db9cc388cf9815386e13465f332">uint32</a> m_findex{0};</div>
<div class="line"><a name="l00075"></a><span class="lineno">   75</span>&#160;    std::string m_fileName{<span class="stringliteral">&quot;&quot;</span>};</div>
<div class="line"><a name="l00076"></a><span class="lineno">   76</span>&#160;    std::shared_ptr&lt;File&gt; m_file{<span class="keyword">nullptr</span>};</div>
<div class="line"><a name="l00077"></a><span class="lineno">   77</span>&#160;    std::unique_ptr&lt;char[]&gt; m_logBufPtr;</div>
<div class="line"><a name="l00078"></a><span class="lineno">   78</span>&#160;    <a class="code" href="classlibemb_1_1_mutex.html">Mutex</a> m_mutex;</div>
<div class="line"><a name="l00079"></a><span class="lineno">   79</span>&#160;};</div>
<div class="line"><a name="l00080"></a><span class="lineno">   80</span>&#160; </div>
<div class="line"><a name="l00085"></a><span class="lineno"><a class="line" href="classlibemb_1_1_logger_manager.html">   85</a></span>&#160;<span class="keyword">class </span><a class="code" href="classlibemb_1_1_logger_manager.html">LoggerManager</a>:<span class="keyword">public</span> <a class="code" href="classlibemb_1_1_singleton.html">Singleton</a>&lt;LoggerManager&gt;{</div>
<div class="line"><a name="l00086"></a><span class="lineno">   86</span>&#160;<a class="code" href="_base_type_8h.html#a57e803e49526dc5ba8c1915c68708ae0">DECL_CLASSNAME</a>(<a class="code" href="classlibemb_1_1_logger_manager.html">LoggerManager</a>)</div>
<div class="line"><a name="l00087"></a><span class="lineno">   87</span>&#160;<a class="code" href="_singleton_8h.html#adbe81dabafd4a18fb17e8780c0a9190d">DECL_SINGLETON</a>(<a class="code" href="classlibemb_1_1_logger_manager.html">LoggerManager</a>)</div>
<div class="line"><a name="l00088"></a><span class="lineno">   88</span>&#160;<span class="keyword">public</span>:</div>
<div class="line"><a name="l00089"></a><span class="lineno">   89</span>&#160;    <span class="keyword">virtual</span> ~<a class="code" href="classlibemb_1_1_logger_manager.html">LoggerManager</a>();</div>
<div class="line"><a name="l00094"></a><span class="lineno">   94</span>&#160;    <span class="keywordtype">void</span> <a class="code" href="classlibemb_1_1_logger_manager.html#a0e793558661362cf0510d7f98a8d03c9">setRoot</a>(<span class="keyword">const</span> std::string&amp; logDir);</div>
<div class="line"><a name="l00105"></a><span class="lineno">  105</span>&#160;    <span class="keywordtype">bool</span> <a class="code" href="classlibemb_1_1_logger_manager.html#abbfb81e4a48511453345c96466e1b4ec">createLogger</a>(<span class="keyword">const</span> std::string&amp; logName,<span class="keywordtype">int</span> maxSize, <span class="keywordtype">int</span> rotations=0);</div>
<div class="line"><a name="l00112"></a><span class="lineno">  112</span>&#160;    std::shared_ptr&lt;Logger&gt; <a class="code" href="classlibemb_1_1_logger_manager.html#a80a19c32c8089b78829e4c6328565fe1">getLogger</a>(<span class="keyword">const</span> std::string logName);</div>
<div class="line"><a name="l00113"></a><span class="lineno">  113</span>&#160;<span class="keyword">private</span>:</div>
<div class="line"><a name="l00114"></a><span class="lineno">  114</span>&#160;    std::map&lt;std::string, std::shared_ptr&lt;Logger&gt;&gt; m_loggerMap;</div>
<div class="line"><a name="l00115"></a><span class="lineno">  115</span>&#160;    std::string m_logDir{<span class="stringliteral">&quot;&quot;</span>};</div>
<div class="line"><a name="l00116"></a><span class="lineno">  116</span>&#160;};</div>
<div class="line"><a name="l00117"></a><span class="lineno">  117</span>&#160; </div>
<div class="line"><a name="l00118"></a><span class="lineno">  118</span>&#160;}</div>
<div class="line"><a name="l00119"></a><span class="lineno">  119</span>&#160; </div>
<div class="line"><a name="l00120"></a><span class="lineno">  120</span>&#160;<span class="preprocessor">#endif</span></div>
<div class="line"><a name="l00121"></a><span class="lineno">  121</span>&#160; </div>
</div><!-- fragment --></div><!-- contents -->
<div class="ttc" id="aclasslibemb_1_1_logger_html"><div class="ttname"><a href="classlibemb_1_1_logger.html">libemb::Logger</a></div><div class="ttdoc">日志器</div><div class="ttdef"><b>Definition:</b> Logger.h:46</div></div>
<div class="ttc" id="a_date_time_8h_html"><div class="ttname"><a href="_date_time_8h.html">DateTime.h</a></div><div class="ttdoc">日期时间</div></div>
<div class="ttc" id="aclasslibemb_1_1_logger_html_afb9febc35d54467b983d9c894fa715af"><div class="ttname"><a href="classlibemb_1_1_logger.html#afb9febc35d54467b983d9c894fa715af">libemb::Logger::log</a></div><div class="ttdeci">void log(const char *format,...)</div><div class="ttdoc">记录日志</div><div class="ttdef"><b>Definition:</b> Logger.cpp:86</div></div>
<div class="ttc" id="a_singleton_8h_html"><div class="ttname"><a href="_singleton_8h.html">Singleton.h</a></div><div class="ttdoc">单例</div></div>
<div class="ttc" id="aclasslibemb_1_1_logger_html_a9d2c0252219e63431c6c763ccd336b94"><div class="ttname"><a href="classlibemb_1_1_logger.html#a9d2c0252219e63431c6c763ccd336b94">libemb::Logger::close</a></div><div class="ttdeci">void close()</div><div class="ttdoc">关闭日志</div><div class="ttdef"><b>Definition:</b> Logger.cpp:80</div></div>
<div class="ttc" id="aclasslibemb_1_1_mutex_html"><div class="ttname"><a href="classlibemb_1_1_mutex.html">libemb::Mutex</a></div><div class="ttdoc">互斥锁类</div><div class="ttdef"><b>Definition:</b> ThreadUtil.h:43</div></div>
<div class="ttc" id="a_base_type_8h_html_a01991db9cc388cf9815386e13465f332"><div class="ttname"><a href="_base_type_8h.html#a01991db9cc388cf9815386e13465f332">libemb::uint32</a></div><div class="ttdeci">unsigned int uint32</div><div class="ttdef"><b>Definition:</b> BaseType.h:76</div></div>
<div class="ttc" id="aclasslibemb_1_1_logger_manager_html_a80a19c32c8089b78829e4c6328565fe1"><div class="ttname"><a href="classlibemb_1_1_logger_manager.html#a80a19c32c8089b78829e4c6328565fe1">libemb::LoggerManager::getLogger</a></div><div class="ttdeci">std::shared_ptr&lt; Logger &gt; getLogger(const std::string logName)</div><div class="ttdoc">获取日志器</div><div class="ttdef"><b>Definition:</b> Logger.cpp:181</div></div>
<div class="ttc" id="aclasslibemb_1_1_logger_manager_html"><div class="ttname"><a href="classlibemb_1_1_logger_manager.html">libemb::LoggerManager</a></div><div class="ttdoc">日志管理器</div><div class="ttdef"><b>Definition:</b> Logger.h:85</div></div>
<div class="ttc" id="a_singleton_8h_html_adbe81dabafd4a18fb17e8780c0a9190d"><div class="ttname"><a href="_singleton_8h.html#adbe81dabafd4a18fb17e8780c0a9190d">DECL_SINGLETON</a></div><div class="ttdeci">#define DECL_SINGLETON(InstanceClass)</div><div class="ttdef"><b>Definition:</b> Singleton.h:44</div></div>
<div class="ttc" id="a_base_type_8h_html"><div class="ttname"><a href="_base_type_8h.html">BaseType.h</a></div><div class="ttdoc">基础类型头文件</div></div>
<div class="ttc" id="a_file_util_8h_html"><div class="ttname"><a href="_file_util_8h.html">FileUtil.h</a></div><div class="ttdoc">文件工具类</div></div>
<div class="ttc" id="aclasslibemb_1_1_logger_manager_html_abbfb81e4a48511453345c96466e1b4ec"><div class="ttname"><a href="classlibemb_1_1_logger_manager.html#abbfb81e4a48511453345c96466e1b4ec">libemb::LoggerManager::createLogger</a></div><div class="ttdeci">bool createLogger(const std::string &amp;logName, int maxSize, int rotations=0)</div><div class="ttdoc">获取日志器</div><div class="ttdef"><b>Definition:</b> Logger.cpp:154</div></div>
<div class="ttc" id="a_base_type_8h_html_a57e803e49526dc5ba8c1915c68708ae0"><div class="ttname"><a href="_base_type_8h.html#a57e803e49526dc5ba8c1915c68708ae0">DECL_CLASSNAME</a></div><div class="ttdeci">#define DECL_CLASSNAME(ClassName)</div><div class="ttdef"><b>Definition:</b> BaseType.h:176</div></div>
<div class="ttc" id="aclasslibemb_1_1_singleton_html"><div class="ttname"><a href="classlibemb_1_1_singleton.html">libemb::Singleton</a></div><div class="ttdoc">单例模板类</div><div class="ttdef"><b>Definition:</b> Singleton.h:51</div></div>
<div class="ttc" id="a_thread_util_8h_html"><div class="ttname"><a href="_thread_util_8h.html">ThreadUtil.h</a></div><div class="ttdoc">线程工具</div></div>
<div class="ttc" id="aclasslibemb_1_1_logger_html_a08cccade513d4afc838bd5a021959ae8"><div class="ttname"><a href="classlibemb_1_1_logger.html#a08cccade513d4afc838bd5a021959ae8">libemb::Logger::open</a></div><div class="ttdeci">bool open(const std::string &amp;logFileName, uint32 maxSize, uint32 rotations=0)</div><div class="ttdoc">打开日志</div><div class="ttdef"><b>Definition:</b> Logger.cpp:62</div></div>
<div class="ttc" id="aclasslibemb_1_1_logger_manager_html_a0e793558661362cf0510d7f98a8d03c9"><div class="ttname"><a href="classlibemb_1_1_logger_manager.html#a0e793558661362cf0510d7f98a8d03c9">libemb::LoggerManager::setRoot</a></div><div class="ttdeci">void setRoot(const std::string &amp;logDir)</div><div class="ttdoc">设置日志根目录</div><div class="ttdef"><b>Definition:</b> Logger.cpp:149</div></div>
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.18
</small></address>
</body>
</html>
